<!--角色（管理员）管理-->
#if(admin_name.a_id==1)
<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>

		<link rel="stylesheet" href="/static/css/backstage/amazeui.min.css">
		<link rel="stylesheet" href="/static/css/backstage/admin.css" >
		<link rel="stylesheet" href="/static/css/backstage/mobile_alert.css" >
		<!--[if (gte IE 9)|!(IE)]><!-->
		<!-- <script src="http://libs.baidu.com/jquery/1.7.2/jquery.min.js"></script> -->
		<!-- <script src="jquery-1.7.2.min.js"></script> -->
		<!--<![endif]-->
		<!-- <script type="text/javascript" src="plugs.js" ></script> -->
	</head>
	#if(page>admins.totalPages)
	<script>
		window.location.href="/backstage/role?key=${search}&page=${admins.totalPages}";
	</script>
	#end
	<body>

		<div class="admin-content-body">
			<div class="am-cf am-padding am-padding-bottom-0">
				<div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">角色管理</strong><small></small></div>
			</div>

			<hr>

			<div class="am-g">
				<div class="am-u-sm-12 am-u-md-6">
					<div class="am-btn-toolbar">
						<div class="am-btn-group am-btn-group-xs">
							#if(search=="")
							<button type="button" class="am-btn am-btn-default btnAdd">
								<span class="am-icon-plus"></span> 新增
							</button>
							#else
							<button type="button" class="am-btn am-btn-default" onclick="location.href='/backstage/role'">
								<span class="am-icon-chevron-left"></span> 返回
							</button>
							#end
							<button type="button" style="display:none;" class="am-btn am-btn-default am-text-danger morecheck deleteMore">
								<span class="am-icon-trash-o"></span> 删除
							</button>
						</div>
					</div>
				</div>
				<div class="am-u-sm-12 am-u-md-3">
					<div class="am-input-group am-input-group-sm">
						<input type="text" style="color:blue;" placeholder="请输入用户名" id="con" value="${search}" class="am-form-field">
						<span class="am-input-group-btn">
            				<button type="button" class="am-btn am-btn-default search" type="button">搜索</button>
						</span>
					</div>
				</div>
			</div>

			<div class="am-g" style="margin-top: 5px;">
				<div class="am-u-sm-12">
					<form class="am-form">
						<input type="hidden" name="ids" id="ids">
						<table class="am-table am-table-striped am-table-hover table-main">
							<thead>
								<tr>
									<th class="table-id">
										<input id="chkAll" class="chooseall" type="checkbox">
									</th>
									<th>ID</th>
									<th>
										用户名
									</th>
									<th class="table-title">
										备注
									</th>

									<th class="table-set">
										操作
									</th>
								</tr>
							</thead>
							<tbody id="tUser">
							#for(Admin admin : admins.getRows())
								<tr>
									<td><input name="checkbox" value="${admin.a_id}" type="checkbox"></td>
									<td>${admin.a_id}</td>
									<td>
										<a onclick="editRole(${admin.a_id})">${admin.a_username}</a>
									</td>
									<td>${admin.a_realname}</td>
									<td>
										<div class="am-btn-toolbar">
											<div class="am-btn-group am-btn-group-xs">
												<button type="button" onclick="editRole(${admin.a_id})" id="role_701" class="am-btn am-btn-default am-btn-xs am-text-secondary btnedit"><span class="am-icon-pencil-square-o"></span> 编辑</button>
												<button type="button" class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only deleteThis"><span class="am-icon-trash-o"></span> 删除</button></div>
										</div>
									</td>
								</tr>
							#end

							</tbody>
						</table>
						<div class="am-cf">
							共 ${admins.getTotalRows()} 条记录
							#if(search!="")(查询结果）
							#end
							<div class="am-fr">
								<ul class="am-pagination">
									<li class="${admins.isHasPrevPage()  ? '':'am-disabled'}">
										<a href="/backstage/role?key=${search}&page=${admins.getPrevPage()}">«</a>
									</li>
									#set(j=admins.getPageNum()-(admins.getPageNum()%5!=0?admins.getPageNum()%5:5)+1)
									#for(int i : range(j, (j+4) > admins.totalPages ? admins.totalPages : j+4))
									<li class="${i == admins.pageNum  ? 'am-active':''}">
										<a href="/backstage/role?key=${search}&page=${i}">${i}</a>
									</li>
                                    #end
									<li class="${admins.isHasNextPage()  ? '':'am-disabled'}">
										<a href="/backstage/role?key=${search}&page=${admins.getNextPage()}">»</a>
									</li>
								</ul>
							</div>
						</div>
						<hr>
					</form>
				</div>
			</div>
		</div>

		</div>
		<!-- content end -->
		</div>
		</div>
		#include('/backstage/footer.html')
		<script type="text/javascript" src="/static/js/backstage/jquery-1.8.3.js"></script>
		<script type="text/javascript" src="/static/js/backstage/plugs.js" ></script>
		<script type="text/javascript" src="/static/js/backstage/choose.js" ></script>
		<script>
			function editRole(id) {

					$.jq_Panel({
						title: "修改角色",
						iframeWidth: 500,
						iframeHeight: 300,
						url: "editRole/"+id
					});
			}

			function check(){
				var checkID = [];//定义一个空数组
				$("input[name='checkbox']:checked").each(function(j){//把所有被选中的复选框的值存入数组
					 checkID[j] =$(this).val();
				});
				$("#ids").val(checkID);
			}

			$(function() {

				$(".search").click(function(){
					window.location.href="/backstage/role?key="+$("#con").val();
				});

				$(".btnAdd").click(function() {

					$.jq_Panel({
						title: "添加管理员",
						iframeWidth: 500,
						iframeHeight: 350,
						url: "addRole"
					});
					

				});
			});

			$(".deleteThis").click(function() {
					if(confirm('确定删除吗？')){
						$("#ids").val($(this).parents("tr").find("input[name='checkbox']").val());
			        	$.ajax({
							url:"/backstage/role_delete",
							dataType:"json",
							type:"post",
							data:$("form").serialize(),
							success:function(result){
								alert("删除成功！");
								window.location.href=location.href;
							},
							error:function(result){
              				  	alert("系统繁忙！");
           					 }
						});
						<!--$(this).parents("tr").remove();-->
					}
			});
			$(".deleteMore").click(function() {
					if(confirm('确定删除吗？')){
						check();
        				$.ajax({
							url:"/backstage/role_delete",
							dataType:"json",
							type:"post",
							data:$("form").serialize(),
							success:function(result){
								alert(result.tips+"个角色删除成功！");
								window.location.href=location.href;
							},
							error:function(result){
              				  	alert("系统繁忙！");
           					 }
						});
						<!--$('tbody input[type=checkbox]:checked').parents("tr").remove();-->
						$("thead input[type='checkbox']").prop("checked", true).click();
					}
			});

		</script>
	</body>

</html>
#else
<script>
	window.location="/backstage";
</script>
#end